package com.project.bean;


import java.time.LocalDate;
import java.util.List;

/**
 * 商品实例
 */
public class ProductBean {
    /**商品编号*/
    private int id;
    /**商品名称*/
    private String name;
    /**商品类别*/
    private String type;
    /**商品制作方法，材质*/
    private String material;
    /**商品适用规格*/
    private String ToDo;
    /**商品包装规格*/
    private String pakage;
    /**商品功用*/
    private String use;
    /**商品产地*/
    private String address;
    /**商品生产日期*/
    private LocalDate productDate;
    /**商品保质期*/
    private String shelf;
    /**商品单价*/
    private int price;
    /**商品图片*/
    private String productImg;
    /**商品状态*/
    private String status = "上架中";
    /**商品是否过期*/
    private String overdue;
    /**商品评价列表*/
    private List<AppraiseBean> productApp;
    /**商品所属门店*/
    private StoreBean store;
    /**商品满意度*/
    private String satisfaction;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getMaterial() {
        return material;
    }

    public void setMaterial(String material) {
        this.material = material;
    }

    public String getToDo() {
        return ToDo;
    }

    public void setToDo(String toDo) {
        ToDo = toDo;
    }

    public String getPakage() {
        return pakage;
    }

    public void setPakage(String pakage) {
        this.pakage = pakage;
    }

    public String getUse() {
        return use;
    }

    public void setUse(String use) {
        this.use = use;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public LocalDate getProductDate() {
        return productDate;
    }

    public void setProductDate(LocalDate productDate) {
        this.productDate = productDate;
    }

    public String getShelf() {
        return shelf;
    }

    public void setShelf(String shelf) {
        this.shelf = shelf;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getProductImg() {
        return productImg;
    }

    public void setProductImg(String productImg) {
        this.productImg = productImg;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public StoreBean getStore() {
        return store;
    }

    public void setStore(StoreBean store) {
        this.store = store;
    }

    /**自动获取商品的过期状态*/
    public String getOverdue() {
        LocalDate today = LocalDate.now();
        int savaDay = (int)(today.toEpochDay()-this.productDate.toEpochDay());
        int numLength = this.shelf.indexOf("年");
        String numShelf = this.shelf.substring(0,numLength);
        int endDay = Integer.parseInt(numShelf) * 365;
        System.out.println(savaDay+"    "+ endDay);
        if(savaDay - endDay >0){
            this.overdue = "已过期";
        }else if(endDay - savaDay <10){
            this.overdue = "临过期";
        }
        else{
            this.overdue = "未过期";
        }
        return overdue;
    }

    public List<AppraiseBean> getProductApp() {
        return productApp;
    }

    public void setProductApp(List<AppraiseBean> productApp) {
        this.productApp = productApp;
    }

    public String getSatisfaction() {
        return satisfaction;
    }

    public void setSatisfaction(String satisfaction) {
        this.satisfaction = satisfaction;
    }

    @Override
    public String toString() {
        return "ProductBean{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", type='" + type + '\'' +
                ", material='" + material + '\'' +
                ", ToDo='" + ToDo + '\'' +
                ", pakage='" + pakage + '\'' +
                ", use='" + use + '\'' +
                ", address='" + address + '\'' +
                ", productDate=" + productDate +
                ", shelf='" + shelf + '\'' +
                ", price=" + price +
                ", productImg='" + productImg + '\'' +
                ", status='" + status + '\'' +
                ", overdue='" + overdue + '\'' +
                ", productApp=" + productApp +
                ", store=" + store +
                ", satisfaction='" + satisfaction + '\'' +
                '}';
    }

    //    public static void main(String[] args){
//       ProjectBean p = new ProjectBean();
//       p.setProductDate(LocalDate.parse("2020-01-10"));
//       p.setShelf("1年");
//       System.out.println(p.getOverdue());
//    }
}
